<?php /*nl2br('size:2808
filestatus:-1
index:0
type:
creationdate:Tue Nov 29 2011 15:21:29 GMT+0800 (PHT)
name:Logout.png
modificationdate:Tue Nov 29 2011 15:21:29 GMT+0800 (PHT)
post:[object Object]
id:SWFUpload_0_0
') */''?>
<?= (isset ($js)?$js:'')?>
<script type="text/javascript">

    jQuery.fn.bindAll = function(options) {
        var $this = this;
        jQuery.each(options, function(key, val){
            $this.bind(key, val);
        });
        return this;
    }

    $(function(){
	
        var listeners = {
            swfuploadLoaded: function(event){
                //$('.log', this).append('<li>Loaded</li>');
            },
            fileQueued: function(event, file){
                
                var html = '';
                html =  '<div index="'+file.index+'" class="progress-wrapper">';
                html += file.name+'<div class="progress-percentage-wrapper"><label class="progress-percentage-label"></label>';
                html += '<label class="progress-percentage"></label></div></div>';
                
                $("#file-wrapper").append(html);
                
                //$('.log', this).append('<li>File queued - '+file.name+'</li>');
                // start the upload once it is queued
                // but only if this queue is not disabled
                if (!$('input[name=disabled]:checked', this).length) {
                    $(this).swfupload('startUpload');
                }
            },
            fileQueueError: function(event, file, errorCode, message){
                //$('.log', this).append('<li>File queue error - '+message+'</li>');
            },
            fileDialogStart: function(event){
                //$('.log', this).append('<li>File dialog start</li>');
            },
            fileDialogComplete: function(event, numFilesSelected, numFilesQueued){
                //$('.log', this).append('<li>File dialog complete</li>');
            },
            uploadStart: function(event, file){
                //$('.log', this).append('<li>Upload start - '+file.name+'</li>');
                // don't start the upload if this queue is disabled
                if ($('input[name=disabled]:checked', this).length) {
                    event.preventDefault();
                }
            },
            uploadProgress: function(event, file, bytesLoaded){
                //$('.log', this).append('<li>Upload progress - '+bytesLoaded+'</li>');
                animate_progress(file,bytesLoaded);
            },
            uploadSuccess: function(event, file, serverData){
                //$('.log', this).append('<li>Upload success - '+file.name+'</li>');
            },
            uploadComplete: function(event, file){
                animate_progress(file,file.size)
                
                var url = BASE_URL+controller+'/';
                o.preloader({id:1});
                $.post(url, {ajax:true}, function(data){
                    $("#current-page").html(data.html);
                    o.preloader({id:1,hide:true});
                    initialize();
                    //$('div[index="'+file.index+'"]').hide('slow');
                    $('div[index="'+file.index+'"]').animate({opacity:0.25, height:'3px'},500,function(){$(this).remove(); });
                }, 'json');
                
               // $('.log', this).append('<li>Upload complete - '+file.name+'</li>');
                // upload has completed, lets try the next one in the queue
                // but only if this queue is not disabled
                if (!$('input[name=disabled]:checked', this).length) {
                    $(this).swfupload('startUpload');
                }
            },
            uploadError: function(event, file, errorCode, message){
                //$('.log', this).append('<li>Upload error - '+message+'</li>');
            }
        };

        $('.swfupload-control').bindAll(listeners);
	
	
        // start the queue if the queue is already disabled
        $('.swfupload-control input[name=disabled]').click(function(){
            if (!this.checked) {
                $(this).parents('.swfupload-control').swfupload('startUpload');
            }
        });
	
    });
		
    $(function(){
        $('.swfupload-control').each(function(){
            $(this).swfupload({
                upload_url: "<?= BASE_URL.'callback/index/'.$controller.'/upload/'.$user.'/' ?>",
                file_size_limit : "0",
                file_types : "*.*",
                file_types_description : "All Files",
                file_upload_limit : "0",
                flash_url : "<?= IMPORTS_URL . 'ifunk' ?>/vendor/swfupload/swfupload.swf",
                button_image_url : '<?= IMPORTS_URL . 'ifunk' ?>/vendor/swfupload/upload-button.png',
                button_width : 50,
                button_height : 33,
                button_placeholder : $('.button', this)[0],
                debug: false
            });
        });
    });	
    
    function animate_progress(file,bytesLoaded){
        var percent = parseInt((bytesLoaded/file.size)*100) ;   
        //alert(percent);    
        $('.progress-percentage','div[index="'+file.index+'"]').css('width', percent+'%');
        $('.progress-percentage-label','div[index="'+file.index+'"]').html(percent+'%');
    }

</script>
<div id="file-wrapper">

</div>


<p class="spacer"></p>

<div style="width:48%;float:left;">

    <div class="swfupload-control">
        <label><input type="checkbox" name="disabled" class="hide" alt="disable"/></label>
        <ol class="log"></ol>
        <input type="button" class="button" />Click to Upload Files
    </div>

</div>

<p class="spacer"></p>

